home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / GameKit / Examples / PacMan / Maze.h < prev    next >
Text File  |  1995-06-12  |  3KB  |  82 lines

  1.  
  2. // Takes care of the maze;  it knows all the maze templates, parses the "mazes"
  3. // file in the .app wrapper, and knows which dots have been eaten.
  4.  
  5. #import <appkit/appkit.h> 
  6.  
  7. // how many mazes are available
  8. #define MAZES 6
  9.  
  10. // image size in pixels; they are square
  11. #define GHOST_SIZE        16
  12. #define PER_ROW            6    // number of maze blocks per row in Maze.tiff
  13.  
  14. // size of maze in # of images (blocks)
  15. #define BLOCK_WIDTH        21
  16. #define BLOCK_HEIGHT    16
  17.  
  18. // the view _must_ have these dimensions:
  19. #define WIN_WIDTH        GHOST_SIZE * BLOCK_WIDTH
  20. #define WIN_HEIGHT        GHOST_SIZE * BLOCK_HEIGHT
  21.  
  22. // max # of these things:
  23. #define MAX_GHOSTS        4
  24. #define MAX_POWER_DOTS    4
  25.  
  26. // useful macros:
  27. #define sgn(x)        ((x) ? (((x) > 0) ? 1 : -1) : 0)
  28. #define abs(x)        (((x) < 0) ? -(x) : (x))
  29.  
  30. // point values
  31. #define DOTPOINTS 10
  32. #define POWERDOTPOINTS 50
  33.  
  34. // maze parts (indices)
  35. #define GHDOOR    5
  36. #define PLAYER    7
  37. #define GHOST    10
  38. #define EMPTY    8
  39. #define DOT        28
  40. #define POWER    29
  41.  
  42. @interface Maze:Object
  43. {
  44.     id   mazeParts[3];    // NXImage with Maze.tiff in it.
  45.     int  mazeNum;    // which maze is currently displayed; between 0 and MAZES-1
  46.     char mazes[MAZES][BLOCK_WIDTH][BLOCK_HEIGHT];    // holds base maze data
  47.     char maze[BLOCK_WIDTH][BLOCK_HEIGHT];    // holds working copy of maze data
  48.     int  power[MAX_POWER_DOTS * 2];        // locations of power dots
  49.     int  ghosts[MAX_GHOSTS * 2];        // starting ghost locations
  50.     int  player[2];                        // starting player/fruit position
  51.     int  door[2];                        // ghost chamber door position
  52.     int  dots;                            // number of dots left in current maze
  53.     int  dotx, doty;                    // (x, y) of last dot eaten
  54.     BOOL powerDotShown;                    // whether or not to draw a power dot
  55.     BOOL visibleMaze;                    // whether or not to draw the maze
  56.     int  scale;
  57. }
  58.  
  59. - init;
  60. - render:(NXRect *)rect at:(NXPoint *)pos;     // used to render
  61.     // lockfocus in the view where it's drawn first.
  62. - makeMaze:(int)num;                // loads maze into working array and sets
  63.                                     // up ghost/power dot/player locations
  64. - playerPosition:(int *)x :(int *)y;    // return x, y of player/fruit
  65. - doorPosition:(int *)x :(int *)y;    // return x, y of door to ghost chamber
  66. - (const int *)powerDot;            // return pointer to power array
  67. - (const int *)ghosts;                // return pointer to ghosts array
  68. - (BOOL)powerDotAt:(int)x :(int)y;    // return YES if power dot in block
  69. - (BOOL)eatDotAt:(int)x :(int)y;    // return YES if OK, NO if no dot was there
  70. - (int)dots;                        // return the number of dots left in maze
  71. - (BOOL)playerWall:(float)x :(float)y;    // YES if player can't be in block
  72. - (BOOL)monsterWall:(float)x :(float)y;    // YES if ghost can't be in block
  73. - blinkPowerDot;                    // toggle ON/OFF state of power dots
  74. - lastDot:(int *)xx :(int *)yy;        // returns (x,y) of last dot eaten
  75. - visible:(BOOL)flag;                // used to tell us if the maze is visible
  76. - (BOOL)isVisible;                    // used to tell others if maze is visible
  77. - (int)scale;
  78. - setScale:(int)newScale;
  79.  
  80.  
  81. @end
  82.